package com.zhida.smartcontrol.dialog.lampsjjzdialog;

import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;

import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.common.bean.LampSwitchBean;
import com.zhida.smartcontrol.mvp.MVPBaseDialogFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.OnClick;

/**
 * author: tanjianpei
 * date: 2019/12/3 003 14:01
 * description: 单双灯时间校准
 */
public class LampSjjzDialogFragment extends MVPBaseDialogFragment<LampSjjzDialogContract.View, LampSjjzDialogPresenter> implements LampSjjzDialogContract.View {

    private int mSwitchType;
    private List<LampSwitchBean> mLampList;

    public static LampSjjzDialogFragment newInstance(int switchType, List<LampSwitchBean> data) {
        Bundle args = new Bundle();
        args.putInt("type", switchType);
        args.putParcelableArrayList("list", (ArrayList<? extends Parcelable>) data);
        LampSjjzDialogFragment fragment = new LampSjjzDialogFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected Object getLayout() {
        return R.layout.dialog_sjjz;
    }

    @Override
    protected void initDatas(Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        if (null == bundle) {
            return;
        }
        mSwitchType = bundle.getInt("type");
        mLampList = bundle.getParcelableArrayList("list");
    }

    @OnClick({R.id.btn_cancel, R.id.btn_confirm})
    public void click(View v) {
        switch (v.getId()) {
            case R.id.btn_cancel:
                dismiss();
                break;
            case R.id.btn_confirm:
                mPresenter.requestTime(mSwitchType, mLampList);
                break;
        }
    }

    @Override
    public void onSuccess() {
        dismiss();
    }

}
